/**
 * Package:com.goldcitynet.flex;
 * $Id: MessagePush.java,v 1.11 2009/06/19 08:01:54 yangc Exp $
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.engine.api.as3;

import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;
import flex.messaging.MessageBroker;

import java.util.Map;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

/**
 * Flex 消息推送类,包含一些便利方法,发布消息给订阅者
 * <p/>
 * <p><a href="MessagePush.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author: yangc $</a>
 * @version $Revision: 1.11 $
 */
public class MessagePush {
    private static Log log = LogFactory.getLog(MessagePush.class);
    public static final String SYSTEM_DESTINATION = "system";
    /**
     * 推送系统消息的底层方法
     *
     * @param headerProperies
     * @param body
     */
    public static void pushSystemMessge(Map headerProperies, Object body) {
        MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
        AsyncMessage msg = new AsyncMessage();
        msg.setHeaders(headerProperies);
        msg.setDestination(SYSTEM_DESTINATION);
        msg.setClientId(UUIDUtils.createUUID());
        msg.setMessageId(UUIDUtils.createUUID());
        msg.setTimestamp(System.currentTimeMillis());
        msg.setBody(body);
        msgBroker.routeMessageToService(msg, null);

    }

}
